package com.hao.tool.extra.poi.word;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * 构造月报echarts的HTML文件
 *
 * @author: lanyh
 * @version: 1.0
 * @date: 2019/2/28 15:46
 * @description:
 */
public class ModifyHTMLUtil {
//    private static final String HTML_FILE_URL = "D:\\project\\质量风控\\青海\\代码库\\trunk\\OperateServiceConsole\\src\\main\\webapp\\assets\\template\\monthlyreport\\";
    //TODO 现场HTML文件路径
    private static final String HTML_FILE_URL = "D:\\HGITS\\apache-tomcat-8.5.29\\webapps\\OperateServiceConsole\\assets\\template\\monthlyreport\\";
    private static final String HTML_HEAD = "<!DOCTYPE html>\n" +
            "<html>\n" +
            "<head>\n" +
            "    <meta charset=\"gbk\"/>\n" +
            "    <script type=\"text/javascript\" src=\"/OperateServiceConsole/assets/scripts/echarts/echarts.min.js\"></script>\n" +
            "</head>\n" +
            "<body>\n" +
            "<div id=\"main\" style=\"width: 750px;height:400px;\"></div>\n" +
            "<script type=\"text/javascript\">\n" +
            "        var myChart = echarts.init(document.getElementById('main'));\n" +
            "        var option = {\n" +
            "            animation: false,\n";
    private static final String HTML_END = "};\n" +
            "        myChart.setOption(option);\n" +
            "</script>\n" +
            "</body>\n" +
            "</html>";


    /**
     * 构造月报echarts的HTML文件
     *
     * @param strHtml     需要构造的string
     * @param htmlFileUrl 修改的html文件路径
     */
    public void modifyHTML(String strHtml, String htmlFileUrl) throws IOException {
        //用于存储html字符串
        //打开文件
//        PrintStream printStream = new PrintStream(new FileOutputStream(HTML_FILE_URL + htmlFileUrl));
        PrintWriter printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(HTML_FILE_URL + htmlFileUrl), StandardCharsets.UTF_8)),true);
        //输入HTML文件内容
        //将HTML文件内容写入文件中
        String stringHtml = HTML_HEAD + strHtml + HTML_END;
        System.out.println(stringHtml);
        printWriter.println(stringHtml);
//        printStream.println(stringHtml);
    }
}